//===============================================================================
// Microsoft patterns & practices
// Guidance Explorer Offline Client
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================



using System;
using System.Collections.Generic;
using System.Windows.Forms;
using GuidanceExplorer.Controls;

namespace GuidanceExplorer.Model
{
    public class NewGuidanceTypeItemMenuItemProvider : IMenuItemsProvider
    {
        #region IMenuItemsProvider Members

        public MenuItemAttribute[] GetSubMenuItems(MenuItemAttribute parent, IModelItem modelItem)
        {
            GuidanceTypeNode guidanceTypeNode = modelItem as GuidanceTypeNode;

            if (guidanceTypeNode.ModelInstance.IsDeleted)
            {
                return new MenuItemAttribute[] { };
            }
            else
            {
                GuidanceType guidanceType = guidanceTypeNode.ModelInstance;

                if (!string.IsNullOrEmpty(guidanceType.NodeDisplayName))
                {
                    List<GuidanceType> allTypes = GuidanceType.AllGuidanceTypes;
                    List<MenuItemAttribute> retAttributes = new List<MenuItemAttribute>(allTypes.Count);

                    foreach (GuidanceType type in allTypes)
                    {
                        if (!string.IsNullOrEmpty(type.NodeDisplayName) &&
                            string.Compare(type.NodeDisplayName, guidanceType.NodeDisplayName) == 0)
                        {
                            retAttributes.Add(new MenuItemAttribute(retAttributes.Count, string.Format("New {0}", type.NewGuidanceTypeDisplayName), type.Name, Keys.None));
                        }
                    }

                    Comparison<MenuItemAttribute> comp = delegate(MenuItemAttribute att1, MenuItemAttribute att2)
                    {
                        return String.Compare(att1.MenuItemName, att2.MenuItemName);
                    };
                    retAttributes.Sort(comp);

                    return retAttributes.ToArray();
                }
                else
                {
                    return new MenuItemAttribute[] { new MenuItemAttribute(0, string.Format("New {0}", guidanceTypeNode.ModelInstance.NewGuidanceTypeDisplayName), guidanceTypeNode.ModelInstance.Name, Keys.None) };
                }
            }
        }

        #endregion
    }
}

